package com.th.supcom.pds.drugsupply.server;

import java.util.List;

import net.carefx.framework.container.client.exception.UiException;
import net.carefx.framework.util.ConvertUtils;
import net.carefx.framework.web.gwt.server.GwtController;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
import com.extjs.gxt.ui.client.data.PagingLoadConfig;
import com.extjs.gxt.ui.client.data.PagingLoadResult;
import com.th.supcom.pds.domain.pojo.PhamBasicInfo;
import com.th.supcom.pds.domain.pojo.PhamPropertyTable;
import com.th.supcom.pds.domain.vo.DrugInfoVO;
import com.th.supcom.pds.domain.vo.DrugSearchVO;
import com.th.supcom.pds.drugsupply.client.model.DrugInfoModel;
import com.th.supcom.pds.drugsupply.client.model.DrugSearchModel;
import com.th.supcom.pds.drugsupply.client.service.PdsPropertyMaintainRpc;
import com.th.supcom.pds.internal.api.DrugMaintainService;

/**
 * 供药属性维护 控制层.
 * 
 * 药品信息.
 */
public class PdsServiceController extends GwtController implements PdsPropertyMaintainRpc
{

    /** 公司版权信息. */
    public static final String copyright = "Copyright 2014, TH Supcom Corporation";
    /** 日志记录器. */
    private static final Logger s_logger = LoggerFactory.getLogger (PhamBasicInfo.class);

    /** 提交路径. */
    public static final String SCC_BRANCH = "$URL$";

    /** 提交日期. */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";

    /** 最终修改人员. */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";

    /** 最终版本号. */
    public static final String SCC_REVISION = "$Revision$";

    /**
     * add by Zli
     */
    private static final long serialVersionUID = -7252559535751128820L;

    private DrugMaintainService m_drugMaintainService;

    /**
     * 默认构造函数.
     */
    public PdsServiceController ()
    {

    }

    public DrugMaintainService getDrugMaintainService ()
    {

        return m_drugMaintainService;
    }

    @Override
    public DrugInfoModel getPhamBasicInfoById (final Long id) throws UiException
    {
        return null;
    }

    @Override
    public PagingLoadResult <DrugInfoModel> getPhamBasicInfoListWithPaging (final PagingLoadConfig config, final DrugSearchModel vo) throws UiException
    {

        final DrugSearchVO vo2 = ConvertUtils.convert (DrugSearchVO.class, vo);
        final List <DrugInfoVO> volist = m_drugMaintainService.getDrugBasicInfo (vo2, config.getOffset (), config.getLimit ());
        final int count = m_drugMaintainService.getDrugBasicInfoCount (vo2);
        final List <DrugInfoModel> drugInfoModelList = ConvertUtils.convert (DrugInfoModel.class, volist);
        return new BasePagingLoadResult <DrugInfoModel> (drugInfoModelList, config.getOffset (), count);
    }

    @Override
    public PagingLoadResult <DrugInfoModel> getPhamBasicInfoListWithPagingByName (final PagingLoadConfig config, final String name, String deptCode)
    {
        PdsServiceController.s_logger.debug ("进入getPhamBasicInfoListWithPagingByName方法,入参:");
        final List <DrugInfoVO> volist = m_drugMaintainService.getDrugBasicInfoByName (name, deptCode, config.getOffset (), config.getLimit ());
        final int count = m_drugMaintainService.getDrugBasicInfoCountByName (name, deptCode);
        final List <DrugInfoModel> drugInfoModelList = ConvertUtils.convert (DrugInfoModel.class, volist);
        return new BasePagingLoadResult <DrugInfoModel> (drugInfoModelList, config.getOffset (), count);

    }

    @Override
    public void modifyPhamBasicInfo (final List <DrugInfoModel> modelList, String deptCode) throws UiException
    {
        final List <PhamPropertyTable> phamPropertyTableList = ConvertUtils.convert (PhamPropertyTable.class, modelList);
        m_drugMaintainService.modifyDrugProperty (phamPropertyTableList, deptCode);

    }

    @Override
    public PagingLoadResult <DrugInfoModel> searchPhamBasicInfoListWithPagingByName (final PagingLoadConfig config, final String name, String deptCode)
    {
        PdsServiceController.s_logger.debug ("进入searchPhamBasicInfoListWithPagingByName方法,入参:");

        final List <DrugInfoVO> volist = m_drugMaintainService.searchDrugBasicInfoByName (name, deptCode, config.getOffset (), config.getLimit ());
        final int count = m_drugMaintainService.searchDrugBasicInfoCountByName (name, deptCode);
        final List <DrugInfoModel> drugInfoModelList = ConvertUtils.convert (DrugInfoModel.class, volist);
        return new BasePagingLoadResult <DrugInfoModel> (drugInfoModelList, config.getOffset (), count);

    }

    public void setDrugMaintainService (final DrugMaintainService drugMaintainService)
    {

        m_drugMaintainService = drugMaintainService;
    }
}